|
|
|
|
|
|
|
Three-Dimensional Objects |
|
|
|
|
|
|
|
|
As is the case in two dimensions, you can use Visual Basic's classes to manage three-dimensional objects more easily. At a minimum, such an object should be able to store points for drawing, apply a transformation to those points, and draw the transformed points on a picture box, form, or printer. |
|
|
|
|
|
|
|
|
The Polyline3d class in module Pline3d.cls represents a collection of three-dimensional line segments. It contains an array of points and an array that indicates which points should be connected. |
|
|
|
|
|
|
|
|
Polyline3d objects use the private function AddPoint to add new points to its point array. This function first checks to see if the point is already in the array. If so, the function reuses that point rather than creating a duplicate entry. This saves time later when you want to transform the Polyline3d object. You need to transform each point only once rather than once for each of the segments that contains it. |
|
|
|
 |
|
|
|
|
Option Explicit
' Point3D and Segment3D are defined in module M3OPS.BAS as:
' Type Point3D
' coord(1 To 4) As Single
' trans(1 To 4) As Single
' End Type
'
' Type Segment3D
' pt1 As Integer
' pt2 As Integer
' End Type
Private NumPoints As Integer ' Number of points. Private Points() As Point3D ' Data points.
Private NumSegs As Integer ' Number of segments. Private Segs() As Segment3D ' The segments.
' Add a point to the polyline or reuse a point.
' Return the point's index. Private Function AddPoint(ByVal x As Single, _
ByVal y As Single, ByVal z As Single) As Integer
Dim i As Integer
' See if the point is already here. For i = 1 To NumPoints
If x = Points(i).coord(1) And _
y = Points(i).coord(2) And _
z = Points(i).coord(3) Then _
Exit For |
|
|
|
|
|